<template>
    <div class="warpper">
        <TopHeader  centerMsg="提币"/>
        <van-form  label-width="80px">
            <van-field
                    v-model="form.walletAddress"
                    :disabled="$route.query.walletAddress ? true : false "
                    name="提币地址"
                    label="提币地址"
                    placeholder="输入火币钱包地址"
            />
            <van-field
                    v-model="form.coin"
                    name="提币数量"
                    label="提币数量"
                    type="tel"
                    placeholder="提币数量"
            >
                <template #button>
                    <van-button  @click="allCoin"  size="small" type="primary">全部提取</van-button>
                </template>
            </van-field>
            <div style="margin: 16px;">
                <van-button round block type="info" @click="tbConfrim" :disabled="btnDisabled" native-type="submit">提交</van-button>
            </div>
        </van-form>
    </div>
</template>

<script>
    import TopHeader from '@/components/TopHeader.vue'
    import {tb} from "@/utils/request"
    import {mapState} from 'vuex'
    import {Toast} from "vant";
    export default {
        name: "extract",
        components: {
            TopHeader,
        },
        data () {
            return {
                form: {
                    walletAddress: this.$route.query.walletAddress || '',
                    coin: '',
                },
                // 最大提币数量
                maxNum: this.$route.query.maxNum || 0,
                loading: false,
            }
        },
        computed:{
            ...mapState([
            ]),
            btnDisabled() {
                let flag = false;
                if (!this.form.walletAddress || !this.form.coin || this.loading ) {
                    flag = true;
                }
                return flag;
            }
        },
        methods:{
            tbConfrim() {
                this.loading = true;
                let params = {
                    walletAddress: this.form.walletAddress,
                    coin: this.form.coin
                }
                tb(params).then(res => {
                    if (res.code === 200) {
                        Toast.success(res.msg || '申请提取成功');
                        setTimeout(() => {
                            this.$router.push({
                                path: '/personal'
                            })
                        }, 500);
                    } else {
                        Toast.fail(res.msg || '请求失败');
                    }
                    setTimeout(() => {
                        this.loading = false;
                    }, 300)
                }).catch(() => {
                    setTimeout(() => {
                        this.loading = false;
                    }, 300)
                });
            },
            allCoin() {
                this.form.coin = this.maxNum;
            }

        }
    }
</script>

<style scoped lang='less'>
    .warpper{
        padding-top: 2.8rem;
    }

</style>

